<template>
    <div class="text-center">
        <div class="font-16 font-weight" v-if="excelstatus == 'processing' || excelstatus == 'pending'">处理中...</div>
        <div class="margin-top-10">小贴士：当前操作系统处理中，如不想在本页面等待处理结果，可关闭提示，关闭后可在<span class="font-14 color-error">右上角铃铛的任务标签</span>查看最新状态，处理完成也可以通过<span class="font-14 color-error">右上角铃铛的任务标签</span>进行文件下载</div>
        <div class="margin-top-10 margin-bottom-10 font-14 font-weight">如继续等待请保持窗口打开，请稍后...</div> 
        <div class="margin-top-10 margin-bottom-10 font-14 font-weight" v-if="excelstatus == 'success'">
            处理完成！<a class="margin-top-10 font-16" style="text-decoration:underline" @click="dowmExcel">点击下载</a>
        </div> 
        <div class="margin-top-10 margin-bottom-10 font-14 font-weight" v-if="excelstatus == 'failed'">
            处理失败！请到<span class="font-14 color-error">右上角铃铛的任务标签</span>查看详情
        </div> 
        
        <div class="text-right">
            <Button @click="close">关闭</Button>
        </div>
    </div>
</template>

<script>
import { HttpAllTaskExport,HttpTaskCenter } from "../../service/notice";
export default {
    props:['actionurl'],
    data(){
        return {
            count:5,
            excelstatus:'processing',
            downurl:'',
            taskid:'',
            showAlert:true,
        }
    },
    created(){
        this.countDown();
        // 请求页面下载链接
        this.getExcelLink()
    },
    methods:{
        close(){
            this.showAlert = false;
            this.$emit('on-close')
        },
        countDown(){
            setTimeout(()=>{
                if(this.count>1){
                    this.countDown()
                }else{
                    this.getOneTask()
                }
                this.count --;
            },1000)
        },
        getExcelLink(type){
            HttpAllTaskExport().then(res=>{
                this.taskid = res.data.id
                // this.downurl = res.data.taskFile
            })
        },
        getOneTask(){
            HttpTaskCenter({
                id:this.taskid
            }).then(res=>{
                this.excelstatus = res.data.status
                if((this.excelstatus == 'processing' || this.excelstatus == 'pending') && this.showAlert){
                    this.count = 5;
                    this.countDown();
                    return
                }
                this.downurl = res.data.taskFile
            })
        },
        dowmExcel(url){
            // event.preventDefault();
            this.handleWebfs(this.downurl, {}, 'download')
        }
    }
}
</script>